package com.yet.kotlinapp.modules.home

import com.blankj.utilcode.util.LogUtils
import com.kongzue.dialogx.dialogs.WaitDialog
import com.yet.kotlinapp.api.WangAndroidApi
import com.yet.kotlinapp.entity.BannerResponseInfo
import com.yet.kotlinapp.modules.home.inter.HomeModel
import com.yet.kotlinapp.modules.home.inter.HomePresente
import com.yet.kotlinapp.net.ApiClient
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Observer
import io.reactivex.rxjava3.core.Scheduler
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import java.util.*

/**
 *
 * @ProjectName: Kotlin app
 * @Package: com.yet.kotlinapp.modules.home.inter
 * @ClassName: HomeModelImp
 * @Description: java类作用描述
 * @Author: liys
 * @CreateDate: 2021/8/30 17:41
 * @UpdateUser: 更新者
 * @UpdateDate: 2021/8/30 17:41
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */

class HomeModelImp :HomeModel{


    override fun getBanner(homePresente: HomePresente.onbanner) {
        ApiClient.instance.instanceRetrofit(WangAndroidApi::class.java)
            .getBannerAction()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object :Observer<BannerResponseInfo>{
                override fun onSubscribe(d: Disposable?) {
                    WaitDialog.show("Please Wait!");
                }

                override fun onNext(t: BannerResponseInfo?) {
                    LogUtils.d(t)
                    t?.let { homePresente.onSuccess(it) }
                }

                override fun onError(e: Throwable?) {
                    LogUtils.d(e)
                    WaitDialog.dismiss()

                }

                override fun onComplete() {
                    WaitDialog.dismiss()
                }

            })
    }

}